package thread.threadpool;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author lwmzzz
 * @version 1.0
 * @date 2021/5/19 0:09
 * @description
 */
public class Test02 {
    public static void main(String[] args) {
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(10);

        scheduledExecutorService.schedule(() -> System.out.println(Thread.currentThread().getId() + "===" + System.currentTimeMillis()), 2, TimeUnit.SECONDS);
        scheduledExecutorService.scheduleAtFixedRate(() -> System.out.println(Thread.currentThread().getId() + "===" + System.currentTimeMillis()), 2, 5, TimeUnit.SECONDS);
        scheduledExecutorService.scheduleWithFixedDelay(() -> System.out.println(Thread.currentThread().getId() + "==上次任务结束后，每两秒重复执行==" + System.currentTimeMillis()), 2, 1, TimeUnit.SECONDS);
    }
}
